﻿//准备ExtJS环境
Ext.require
( 
    [
        'Ext.form.field.File',
        'Ext.grid.*',
        'Ext.data.*',
        'Ext.util.*',
        'Ext.state.*',
        'Ext.form.*'
    ]
);

//定义用户表格控件
Ext.define
( 
    'Project.Grid',
    {
        extend: 'Ext.grid.Panel',

        //编辑窗体
        win_edi: null,

        //检索窗体
        win_search: null,

        //附件管理窗体
        win_attachment: null,

        //初始化组件
        initComponent: function ()
        {
            Ext.apply
            ( 
                this,
                {
                    dockedItems:
                    [
                        {
                            xtype: 'toolbar',
                            height: 36,
                            items:
                            [
                                {
                                    iconCls: 'icon-refresh',
                                    text: '刷新',
                                    scope: this,
                                    hidden: false,
                                    tooltip: '刷新数据',
                                    handler: this.onRefreshClick
                                },
                                '-',
                                {
                                    iconCls: 'icon-edit',
                                    text: '编辑',
                                    itemId: 'button-edit',
                                    disabled: true,
                                    hidden: button_edit_hidden,
                                    scope: this,
                                    tooltip: '编辑工程项目',
                                    handler: this.onEditClick
                                },
                                {
                                    iconCls: 'icon-upload',
                                    text: '管理附件',
                                    itemId: 'button-upload',
                                    scope: this,
                                    disabled: true,
                                    hidden: button_upload_hidden,
                                    tooltip: '管理项目相关附件',
                                    handler: this.onUploadClick
                                },
                                {
                                    iconCls: 'icon-view',
                                    text: '查看',
                                    itemId: 'button-view',
                                    disabled: true,
                                    hidden: false,
                                    scope: this,
                                    tooltip: '查看工程项目详细信息',
                                    handler: this.onViewClick
                                },
                                {
                                    iconCls: 'icon-plan',
                                    xtype: 'splitbutton',
                                    text: '工程计划',
                                    itemId: 'button-plan',
                                    disabled: true,
                                    hidden: false,
                                    scope: this,
                                    tooltip: '查看工程计划详细信息',
                                    handler: this.onViewPlanClick,
                                    menu:
                                    {
                                        xtype: 'menu',
                                        plain: true,
                                        defaults:
                                        {
                                            scale: 'large',
                                            iconAlign: 'left'
                                        },
                                        items:
                                        [
                                            {
                                                iconCls: 'icon-history',
                                                cls: 'grid-menu',
                                                text: '工程计划履历',
                                                tooltip: '查看工程计划履历信息',
                                                handler: this.onViewPlanHistoryClick
                                            },
                                            {
                                                iconCls: 'icon-edit',
                                                disabled: button_editpaln_hidden,
                                                text: '修改工程计划',
                                                tooltip: '修改当前工程计划',
                                                handler: this.onEditPlanClick
                                            }
                                        ]
                                    }
                                },
                                {
                                    iconCls: 'icon-search',
                                    text: '检索',
                                    itemId: 'quantity-search',
                                    scope: this,
                                    hidden: false,
                                    tooltip: '检索工程项目',
                                    handler: this.onSearchClick
                                },
                                '->',
                                {
                                    iconCls: 'icon-close',
                                    text: '关闭',
                                    itemId: 'button-close',
                                    scope: this,
                                    disabled: true,
                                    hidden: false,
                                    tooltip: '关闭工程项目',
                                    handler: this.onCloseClick
                                }
                            ]
                        }
                    ],
                    listeners:
                    {
                        //设置两个指头的滚动
                        render: Common.ScrollableRender
                    }
                }
            );
            this.callParent();
            this.getSelectionModel().on( 'selectionchange', this.onSelectionChange, this );
        },

        //处理选中项目变化事件
        onSelectionChange: function ( selectionModel, selections )
        {
            //判断是否选中项目
            if ( selections.length === 0 )
            {
                //禁用编辑按钮
                this.down( '#button-edit' ).setDisabled( true );
                //禁用上传按钮
                this.down( '#button-upload' ).setDisabled( true );
                //禁用查看按钮
                this.down( '#button-view' ).setDisabled( true );
                //禁用关闭按钮
                this.down( '#button-close' ).setDisabled( true );
                //禁用工程计划按钮
                this.down( '#button-plan' ).setDisabled( true );
            }
            else
            {
                //获得选中项目
                var selection = selections[0];

                //启用编辑按钮
                this.down( '#button-edit' ).setDisabled( false );
                //启用上传按钮
                this.down( '#button-upload' ).setDisabled( false );
                //启用查看按钮
                this.down( '#button-view' ).setDisabled( false );
                //启用关闭按钮
                this.down( '#button-close' ).setDisabled( selection.data.State != ProjectStateEnum.Audited );
                //启用查看计划按钮
                this.down( '#button-plan' ).setDisabled( false );
            }
        },

        //处理关闭按钮点击事件
        onCloseClick: function ()
        {
            //获得数据存储对象
            var store = this.store;

            //获得选中的行
            var selection = this.getView().getSelectionModel().getSelection();

            //判断是否选中行
            if ( selection.length > 0 )
            {
                //询问是否确定删除
                Ext.Msg.show
                ( 
                    {
                        title: '关闭',
                        width: 320,
                        height: 240,
                        msg: '确定要关闭工程项目"' + selection[0].data.ProjectName + '"吗?',
                        buttons: Ext.Msg.YESNO,
                        icon: Ext.Msg.QUESTION,
                        fn: function ( button )
                        {
                            //判断是否确定删除 
                            if ( button == 'yes' )
                            {
                                //创建请求对象
                                Ext.Ajax.request
                                ( 
                                    {
                                        url: Common.MakeAbsoluteUrl( 'ExecuteClose' ),
                                        method: HttpMethod.Post,
                                        params:
                                        {
                                            projectID: selection[0].data.ProjectID
                                        },
                                        callback: function ( options, success, response )
                                        {
                                            //处理错误
                                            if ( Common.HandleError( options, success, response ) )
                                            {
                                                //加载数据
                                                store.load();
                                            }
                                        }
                                    }
                                );
                            }
                        }
                    }
                );
            }
        },

        //查看工程计划
        onViewPlanClick: function ()
        {
            //获得选中的行
            var selection = this.getView().getSelectionModel().getSelection();

            //判断是否选中行
            if ( selection.length > 0 )
            {
                //查看工程详细信息
                window.open( Common.MakeControllerUrl( 'ProjectPlan', 'ViewProjectPlan?projectID=' + selection[0].data.ProjectID ) );
            }
        },

        //查看工程计划履历
        onViewPlanHistoryClick: function ()
        {
            //获得表格控件
            var grid = Ext.getCmp( 'project-grid' );

            //获得选中的行
            var selection = grid.getSelectionModel().getSelection();

            //判断是否选中行
            if ( selection.length > 0 )
            {
                //查看工程详细信息
                window.open( Common.MakeControllerUrl( 'ProjectPlan', 'ViewProjectPlanHistory?projectID=' + selection[0].data.ProjectID ) );
            }
        },

        //编辑工程计划
        onEditPlanClick: function ()
        {
            //获得表格控件
            var grid = Ext.getCmp( 'project-grid' );

            //获得选中的行
            var selection = grid.getSelectionModel().getSelection();

            //判断是否选中行
            if ( selection.length > 0 )
            {
                //查看工程详细信息
                window.open( Common.MakeControllerUrl( 'ProjectPlan', 'Modify?projectID=' + selection[0].data.ProjectID ) );
            }
        },

        //文件上传成功回调
        onFileUploadSuccess: function ( response, options )
        {
            //判定是否有所属编号
            if ( options.OwnerID )
            {
                //如果有所属编号，则刷新附件数据
                store_attachment.load();
            }
        },

        //管理附件
        onManageAttachment: function ( projectID )
        {
            //判定窗体是否创建
            if ( !this.win_attachment )
            {
                //创建表格
                var grid_attachment = new Ext.grid.GridPanel
                ( 
                    {
                        store: store_attachment,
                        border: 0,
                        stateful: true,
                        height: '100%',
                        width: '100%',
                        viewConfig:
                        {
                            stripeRows: true,
                            loadingText: '数据加载中...',
                            singleSelect: true
                        },
                        columns:
                        [
                            {
                                text: '附件名称',
                                flex: 1,
                                sortable: false,
                                align: 'left',
                                dataIndex: 'AttachmentName',
                                hideable: false
                            },
                            {
                                text: '公开附件',
                                width: 80,
                                sortable: false,
                                align: 'center',
                                renderer: renderGridReadonlyCheckBox,
                                dataIndex: 'IsOpen',
                                hideable: false
                            },
                            {
                                text: '文件类型',
                                width: 80,
                                sortable: false,
                                align: 'left',
                                dataIndex: 'FileExtension',
                                hideable: false
                            }
                        ],
                        dockedItems:
                        [
                            {
                                xtype: 'toolbar',
                                height: 36,
                                items:
                                [
                                    {
                                        iconCls: 'icon-add',
                                        text: '上传附件',
                                        scope: this,
                                        hidden: false,
                                        tooltip: '上传项目附件',
                                        handler: function ()
                                        {
                                            //获得表格控件
                                            var grid = Ext.getCmp( 'project-grid' );

                                            //上传附件
                                            UploadFile
                                            ( 
                                                {
                                                    title: '上传附件',
                                                    mode: 1,
                                                    FileType: 1,
                                                    file_size_limit: attachment_file_size_limit,
                                                    file_size_limit_tip: attachment_file_size_limit_tip,
                                                    file_types: attachment_file_types,
                                                    file_types_description: attachment_file_types_description,
                                                    url: Common.MakeControllerUrl( 'FileUpload', 'UploadTempFile' ),
                                                    callback: grid.onFileUploadSuccess,
                                                    OwnerID: store_attachment.projectID
                                                }
                                            );
                                        }
                                    },
                                    {
                                        iconCls: 'icon-delete',
                                        itemId: 'attachment-delete',
                                        text: '删除附件',
                                        scope: this,
                                        hidden: false,
                                        disabled: true,
                                        tooltip: '删除项目附件',
                                        handler: function ( button )
                                        {
                                            //获得选中的行
                                            var selection = button.up( 'grid' ).getView().getSelectionModel().getSelection()[0];

                                            //判断是否选中行
                                            if ( selection )
                                            {
                                                //询问是否确定删除
                                                Ext.Msg.show
                                                ( 
                                                    {
                                                        title: '删除附件',
                                                        width: 320,
                                                        height: 240,
                                                        msg: '确定要删除选中的附件"' + selection.data.AttachmentName + '?',
                                                        buttons: Ext.Msg.YESNO,
                                                        icon: Ext.Msg.QUESTION,
                                                        fn: function ( button )
                                                        {
                                                            //判断是否确定删除 
                                                            if ( button == 'yes' )
                                                            {
                                                                //创建请求对象
                                                                Ext.Ajax.request
                                                                ( 
                                                                    {
                                                                        url: Common.MakeAbsoluteUrl( 'DeleteAttachment' ),
                                                                        method: HttpMethod.Post,
                                                                        params: selection.data,
                                                                        callback: function ( options, success, response )
                                                                        {
                                                                            //处理错误
                                                                            if ( Common.HandleError( options, success, response ) )
                                                                            {
                                                                                //刷新数据
                                                                                store_attachment.load();
                                                                            }
                                                                        }
                                                                    }
                                                                );
                                                            }
                                                        }
                                                    }
                                                );
                                            }
                                        }
                                    }
                                ]
                            }
                        ],
                        listeners:
                        {
                            selectionchange: function ( selectionModel, selections )
                            {
                                //判断是否选中项目
                                if ( selections.length === 0 )
                                {
                                    //禁用删除按钮
                                    this.down( '#attachment-delete' ).setDisabled( true );
                                }
                                else
                                {
                                    //禁用删除按钮
                                    this.down( '#attachment-delete' ).setDisabled( false );
                                }
                            },
                            //设置两个指头的滚动
                            render: Common.ScrollableRender

                        }
                    }
                 );

                //创建窗体
                this.win_attachment = new Ext.Window
                ( 
                    {
                        title: '项目附件管理',
                        maximizable: false,
                        maximized: false,
                        width: 540,
                        height: 360,
                        bodyBorder: false,
                        draggable: true,
                        isTopContainer: true,
                        modal: true,
                        resizable: false,
                        bodyPadding: 0,
                        closeAction: 'hide',
                        closable: true,
                        layout: 'fit',
                        items:
                        [
                            grid_attachment
                        ]
                    }
                );
            }

            //设置代理地址
            store_attachment.proxy.url = Common.MakeAbsoluteUrl( 'Attachments?projectID=' + projectID );

            //设置项目编号
            store_attachment.projectID = projectID;

            //加载数据
            store_attachment.load();

            //显示窗体
            this.win_attachment.show();
        },

        //处理刷新按钮点击事件
        onRefreshClick: function ()
        {
            //刷新数据
            this.store.load();
        },

        //处理编辑按钮点击事件
        onEditClick: function ()
        {
            //获得数据存储对象
            var store = this.store;

            //获得选中的行
            var selection = this.getView().getSelectionModel().getSelection()[0];

            //判断是否选中行
            if ( selection )
            {
                //判定窗体是否已经创建
                if ( !this.win_edit )
                {
                    //创建窗体
                    this.win_edit = new Ext.Window
                    ( 
                        {
                            title: '编辑项目',
                            maximizable: false,
                            maximized: false,
                            width: 480,
                            height: 540,
                            autoScroll: false,
                            bodyBorder: false,
                            draggable: true,
                            isTopContainer: true,
                            modal: true,
                            resizable: false,
                            bodyPadding: 0,
                            closeAction: 'hide',
                            closable: false,
                            layout: 'fit',
                            fieldDefaults:
                            {
                                labelAlign: 'left',
                                labelWidth: 72,
                                anchor: '100%'
                            },
                            listeners:
                            {
                                //挂接显示事件
                                show: function ( win, options )
                                {
                                    //查询表单对象对象
                                    var form = win.down( 'form' ).getForm();

                                    //加载数据
                                    form.load
                                    ( 
                                        {
                                            url: Common.MakeAbsoluteUrl( 'Details?id=' + win.current_row.ProjectID ),
                                            waitMsg: '数据加载中...',
                                            failure: function ( form, action )
                                            {
                                                //关闭窗体
                                                win.hide();

                                                //处理错误
                                                Common.HandleFormFailure( form, action );
                                            }
                                        }
                                    );
                                }
                            },
                            items:
                            [
                                {
                                    xtype: 'form',
                                    method: 'POST',
                                    waitMsgTarget: true,
                                    waitTitle: Common.ApplicationName,
                                    frame: false,
                                    bodyPadding: 12,
                                    bodyStyle: 'background-color:White;margin:0;',
                                    bodyBorder: false,
                                    border: 0,
                                    autoScroll: true,
                                    defaultType: 'textfield',
                                    autoScroll: false,
                                    fieldDefaults:
                                    {
                                        labelAlign: 'left',
                                        labelWidth: 72,
                                        anchor: '100%',
                                        msgTarget: 'qtip',
                                        autoFitErrors: true,
                                        disabledCls: ''
                                    },
                                    items:
                                    [
                                        {
                                            xtype: 'hiddenfield',
                                            name: 'ProjectID',
                                            allowBlank: false
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'ProjectCode',
                                            fieldLabel: '项目编号',
                                            emptyText: '40个字符',
                                            allowBlank: false,
                                            maxLength: 40
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'ProjectName',
                                            fieldLabel: '项目名称',
                                            emptyText: '80个字符',
                                            allowBlank: false,
                                            maxLength: 80
                                        },
                                        {
                                            xtype: 'combobox',
                                            name: 'CategoryID',
                                            itemId: 'cboCategory',
                                            fieldLabel: '项目类别',
                                            emptyText: '项目类别',
                                            store: store_master_category,
                                            displayField: 'Name',
                                            valueField: 'ID',
                                            queryMode: 'local',
                                            hideTrigger: false,
                                            forceSelection: true,
                                            typeAhead: true,
                                            autocomplete: true,
                                            allowBlank: false
                                        },
                                        {
                                            xtype: 'combobox',
                                            name: 'Roadway',
                                            itemId: 'cboRoadway',
                                            fieldLabel: '线路名称',
                                            emptyText: '项目线路名称',
                                            store: store_master_roadway,
                                            displayField: 'PinYin',
                                            valueField: 'Name',
                                            queryMode: 'local',
                                            hideTrigger: false,
                                            forceSelection: false,
                                            typeAhead: true,
                                            autocomplete: true,
                                            allowBlank: false,
                                            enableKeyEvents: true
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'BeginStake',
                                            fieldLabel: '起点桩号',
                                            emptyText: '项目起点桩号',
                                            allowBlank: false,
                                            maxLength: 40
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'EndStake',
                                            fieldLabel: '终点桩号',
                                            emptyText: '项目终点桩号',
                                            allowBlank: false,
                                            maxLength: 40
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'GrantNumber',
                                            fieldLabel: '项目批号',
                                            emptyText: '项目文件批号',
                                            allowBlank: true,
                                            maxLength: 80
                                        },
                                        {
                                            xtype: 'datefield',
                                            name: 'StartDate',
                                            id: 'txtStartDate',
                                            fieldLabel: '开工日期',
                                            emptyText: '项目开工日期',
                                            format: 'Y/m/d',
                                            allowBlank: true,
                                            vtype: 'dateRange',
                                            endDateField: 'txtCompletionDate'
                                        },
                                        {
                                            xtype: 'datefield',
                                            name: 'CompletionDate',
                                            id: 'txtCompletionDate',
                                            fieldLabel: '竣工日期',
                                            emptyText: '项目竣工日期',
                                            format: 'Y/m/d',
                                            allowBlank: true,
                                            vtype: 'dateRange',
                                            beginDateField: 'txtStartDate'
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'ProjectLeader',
                                            fieldLabel: '项目负责',
                                            emptyText: '项目负责人姓名',
                                            allowBlank: true,
                                            maxLength: 20
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'TechnicalChief',
                                            fieldLabel: '技术负责',
                                            emptyText: '技术负责人姓名',
                                            allowBlank: true,
                                            maxLength: 20
                                        },
                                        {
                                            xtype: 'textfield',
                                            name: 'QualityChief',
                                            fieldLabel: '质检负责',
                                            emptyText: '质检负责人姓名',
                                            allowBlank: true,
                                            maxLength: 20
                                        },
                                        {
                                            xtype: 'numberfield',
                                            name: 'Budget',
                                            fieldLabel: '建安预算',
                                            emptyText: '建安预算（万元）',
                                            minValue: 0,
                                            allowBlank: true,
                                            decimalPrecision: 2
                                        },
                                        {
                                            xtype: 'numberfield',
                                            name: 'ApprovedBudget',
                                            fieldLabel: '建安批复',
                                            emptyText: '建安批复（万元）',
                                            minValue: 0,
                                            allowBlank: true,
                                            decimalPrecision: 2
                                        }
                                    ],
                                    buttons:
                                    [
                                        {
                                            text: '确定',
                                            height: 26,
                                            margin: 3,
                                            handler: function ()
                                            {
                                                //获得表单对象
                                                var form = this.up( 'form' ).getForm();

                                                //检查数据是否合法
                                                if ( form.isValid() )
                                                {
                                                    //提交数据
                                                    form.submit
                                                ( 
                                                    {
                                                        url: Common.MakeAbsoluteUrl( 'Update' ),
                                                        method: HttpMethod.Post,
                                                        scope: this.up( 'window' ),
                                                        submitEmptyText: false,
                                                        waitTitle: '请稍候',
                                                        waitMsg: '正在保存数据...',
                                                        success: function ( form, action )
                                                        {
                                                            //处理提交错误
                                                            if ( Common.HandleFormError( form, action ) )
                                                            {
                                                                //重置数据
                                                                form.reset();
                                                                //隐藏窗体
                                                                this.hide();
                                                                //刷新数据
                                                                store.load();
                                                            }
                                                        },
                                                        failure: Common.HandleFormFailure
                                                    }
                                                );
                                                }
                                            }
                                        },
                                        {
                                            text: '取消',
                                            height: 26,
                                            margin: 3,
                                            handler: function ()
                                            {
                                                //获得表单对象
                                                var form = this.up( 'form' ).getForm();
                                                //重置数据
                                                form.reset();
                                                //隐藏窗体
                                                this.up( 'window' ).hide();
                                            }
                                        }
                                    ]
                                }
                            ]
                        }
                    );
                }

                //设置当前行
                this.win_edit.current_row = selection.data;

                //显示窗体
                this.win_edit.show();
            }
        },

        //处理查看提交按钮点击事件
        onViewClick: function ()
        {
            //获得选中的行
            var selection = this.getView().getSelectionModel().getSelection();

            //判断是否选中行
            if ( selection.length > 0 )
            {
                //查看工程详细信息
                window.open( Common.MakeAbsoluteUrl( 'ViewProject?' ) + 'projectID=' + selection[0].data.ProjectID );
            }
        },

        //处理上传按钮点击事件
        onUploadClick: function ()
        {
            //获得数据存储对象
            var store = this.store;

            //获得选中的行
            var selection = this.getView().getSelectionModel().getSelection();

            //判断是否选中行
            if ( selection.length > 0 )
            {
                //上传附件
                this.onManageAttachment( selection[0].data.ProjectID );
            }
        },

        //处理检索按钮点击事件
        onSearchClick: function ()
        {
            //获得数据存储对象
            var store = this.store;

            //判定窗体是否已经创建
            if ( !this.win_search )
            {
                //创建窗体
                this.win_search = Ext.create
                ( 
                    'Ext.window.Window',
                    {
                        title: '检索项目',
                        maximizable: false,
                        maximized: false,
                        width: 480,
                        height: 320,
                        autoScroll: false,
                        bodyBorder: false,
                        draggable: true,
                        isTopContainer: true,
                        modal: true,
                        resizable: false,
                        bodyPadding: 0,
                        closeAction: 'hide',
                        closable: false,
                        layout: 'fit',
                        items:
                        [
                            {
                                xtype: 'form',
                                frame: false,
                                bodyPadding: 12,
                                bodyStyle: 'background-color:White;margin:0;',
                                bodyBorder: false,
                                border: 0,
                                defaultType: 'textfield',
                                fieldDefaults:
                                {
                                    labelAlign: 'left',
                                    labelWidth: 72,
                                    anchor: '100%'
                                },
                                items:
                                [
                                    {
                                        xtype: 'combobox',
                                        itemId: 'cboOrganization',
                                        fieldLabel: '所属单位',
                                        store: store_organization,
                                        displayField: 'Name',
                                        valueField: 'ID',
                                        queryMode: 'local',
                                        hideTrigger: false,
                                        forceSelection: false,
                                        typeAhead: true,
                                        autocomplete: true,
                                        allowBlank: true
                                    },
                                    {
                                        xtype: 'checkbox',
                                        itemId: 'chkIsWithChild',
                                        fieldLabel: '',
                                        margin: '5 0 5 80',
                                        boxLabel: '包含下属单位',
                                        allowBlank: true,
                                        value: false,
                                        inputValue: true
                                    },
                                    {
                                        xtype: 'textfield',
                                        itemId: 'txtProjectCode',
                                        fieldLabel: '项目编号',
                                        allowBlank: true
                                    },
                                    {
                                        xtype: 'textfield',
                                        itemId: 'txtProjectName',
                                        fieldLabel: '项目名称',
                                        emptyText: '80个字符',
                                        allowBlank: true,
                                        maxLength: 80
                                    },
                                    {
                                        xtype: 'combobox',
                                        itemId: 'cboCategory',
                                        fieldLabel: '项目类别',
                                        emptyText: '项目类别',
                                        store: store_master_category,
                                        displayField: 'Name',
                                        valueField: 'ID',
                                        queryMode: 'local',
                                        hideTrigger: false,
                                        forceSelection: false,
                                        typeAhead: true,
                                        autocomplete: true,
                                        allowBlank: true
                                    },
                                    {
                                        xtype: 'combobox',
                                        itemId: 'cboRoadway',
                                        fieldLabel: '线路名称',
                                        emptyText: '项目线路名称',
                                        store: store_master_roadway,
                                        displayField: 'PinYin',
                                        valueField: 'Name',
                                        queryMode: 'local',
                                        hideTrigger: false,
                                        forceSelection: false,
                                        typeAhead: true,
                                        autocomplete: true,
                                        allowBlank: true,
                                        enableKeyEvents: true
                                    },
                                    {
                                        xtype: 'panel',
                                        layout: 'column',
                                        border: 0,
                                        items:
                                        [
                                            {
                                                columnWidth: 1 / 2,
                                                xtype: 'datefield',
                                                itemId: 'txtStartDate_L',
                                                fieldLabel: '开工日期',
                                                format: 'Y/m/d',
                                                allowBlank: true,
                                                vtype: 'dateRange',
                                                endDateField: 'txtStartDate_H'
                                            },
                                            {
                                                xtype: 'displayfield',
                                                value: '　　 ~　　 ',
                                                columnWidth: 1 / 6
                                            },
                                            {
                                                columnWidth: 1 / 3,
                                                xtype: 'datefield',
                                                itemId: 'txtStartDate_H',
                                                format: 'Y/m/d',
                                                allowBlank: true,
                                                vtype: 'dateRange',
                                                beginDateField: 'txtStartDate_L'
                                            }
                                        ]
                                    }
                                ],
                                buttons:
                                [
                                    {
                                        text: '确定',
                                        height: 26,
                                        margin: 3,
                                        handler: function ()
                                        {
                                            //获得表单对象
                                            var form = this.up( 'form' );

                                            //检查数据是否合法
                                            if ( form.getForm().isValid() )
                                            {
                                                //隐藏窗体
                                                this.up( 'window' ).hide();

                                                //清除过滤条件
                                                store.filters.clear();

                                                //过滤数据
                                                store.filter
                                                ( 
                                                    [
                                                        {
                                                            property: 'OrganizationID',
                                                            value: form.down( '#cboOrganization' ).getValue()
                                                        },
                                                        {
                                                            property: 'IsWithChild',
                                                            value: form.down('#chkIsWithChild').getValue()
                                                        },
                                                        {
                                                            property: 'ProjectCode',
                                                            value: form.down( '#txtProjectCode' ).getValue()
                                                        },
                                                        {
                                                            property: 'ProjectName',
                                                            value: form.down( '#txtProjectName' ).getValue()
                                                        },
                                                        {
                                                            property: 'CategoryID',
                                                            value: form.down( '#cboCategory' ).getValue()
                                                        },
                                                        {
                                                            property: 'Roadway',
                                                            value: form.down( '#cboRoadway' ).getValue()
                                                        },
                                                        {
                                                            property: 'StartDate_L',
                                                            value: form.down( '#txtStartDate_L' ).getValue()
                                                        },
                                                        {
                                                            property: 'StartDate_H',
                                                            value: form.down( '#txtStartDate_H' ).getValue()
                                                        }
                                                    ]
                                                );
                                            }
                                        }
                                    },
                                    {
                                        text: '取消',
                                        height: 26,
                                        margin: 3,
                                        handler: function ()
                                        {
                                            //隐藏窗体
                                            this.up( 'window' ).hide();
                                        }
                                    }
                                ]
                            }
                            ]
                    }
                );
            }

            //显示窗体
            this.win_search.show();
        }
    }
);

//挂接环境准备完毕事件
Ext.onReady
( 
    function ()
    {
        //初始化快速提示
        Ext.QuickTips.init();

        //设置状态保存提供者（当前设置为Cookie）
        Ext.state.Manager.setProvider( Ext.create( 'Ext.state.CookieProvider', { path: _Current_ActionUrl } ) );

        //初始化附加验证类型
        Common.InitAdditionalValidation();

        //创建线路存储对象
        store_master_roadway = Ext.create
        ( 
            'Ext.data.Store',
            {
                fields: ['Name', 'PinYin'],
                data: master_roadway
            }
        );

        //创建分类
        store_master_category = Ext.create
        ( 
            'Ext.data.Store',
            {
                fields: ['ID', 'Name'],
                data: master_category
            }
        );

        //创建附件数据存储对象
        store_attachment = Ext.create
        ( 
            'Ext.data.Store',
            {
                root: 'data',
                autoLoad: false,
                remoteFilter: true,
                remoteSort: true,
                model: 'ProjectAttachmentModel',
                proxy:
                {
                    type: 'ajax',
                    batchActions: false,
                    reader:
                    {
                        type: 'json',
                        root: 'data'
                    },
                    listeners:
                    {
                        exception: function ( proxy, response, operation, options )
                        {
                            //处理错误
                            Common.HandleProxyError( proxy, response, operation, options );
                        }
                    }
                }
            }
        );

        //创建数据存储
        store_organization = Ext.create
        ( 
            'Ext.data.Store',
            {
                model: 'Organization',
                autoLoad: true,
                proxy:
                {
                    type: 'ajax',
                    url: Common.MakeControllerUrl( 'Organization', 'Reference?includeEmpty=false' ),
                    reader:
                    {
                        type: 'json',
                        root: 'data'
                    }
                }
            }
        );

        //创建数据存储对象
        var store = Ext.create
        ( 
            'Ext.data.Store',
            {
                pageSize: 20,
                autoSync: true,
                autoLoad: true,
                root: 'data',
                remoteFilter: true,
                remoteSort: true,
                model: 'ProjectModal',
                proxy:
                {
                    type: 'ajax',
                    batchActions: false,
                    url: Common.MakeAbsoluteUrl( 'ActiveSelect' ),
                    reader:
                    {
                        type: 'json',
                        root: 'data'
                    },
                    listeners:
                    {
                        exception: function ( proxy, response, operation, options )
                        {
                            //处理错误
                            Common.HandleProxyError( proxy, response, operation, options );
                        }
                    }
                }
            }
        );

        Ext.create
        ( 
            'Project.Grid',
            {
                store: store,
                stateful: true,
                stateId: 'project-state-grid',
                height: 600,
                columnLines: true,
                width: '100%',
                id: 'project-grid',
                title: '',
                renderTo: 'data-grid',
                columnLines: true,
                viewConfig:
                {
                    stripeRows: true,
                    loadingText: '数据加载中...',
                    singleSelect: true
                },
                //创建分页工具栏
                bbar: Ext.create
                ( 
                    'Ext.PagingToolbar',
                    {
                        store: store,
                        displayInfo: true,
                        displayMsg: '第 {0} - 第 {1} 条记录，共 {2} 条记录',
                        emptyMsg: ''
                    }
                ),
                columns:
                [
                    {
                        text: '所属单位',
                        width: 160,
                        sortable: true,
                        align: 'left',
                        dataIndex: 'Organization',
                        hideable: false
                    },
                    {
                        text: '项目编号',
                        width: 160,
                        sortable: true,
                        align: 'left',
                        dataIndex: 'ProjectCode',
                        hideable: false
                    },
                    {
                        text: '项目名称',
                        width: 160,
                        minWidth: 160,
                        flex: 1,
                        sortable: true,
                        align: 'left',
                        dataIndex: 'ProjectName',
                        hideable: false
                    },
                    {
                        text: '项目类别',
                        width: 120,
                        sortable: true,
                        align: 'left',
                        dataIndex: 'Category'
                    },
                    {
                        text: '项目状态',
                        width: 80,
                        sortable: true,
                        align: 'center',
                        dataIndex: 'State',
                        renderer: Common.RenderProjectState
                    },
                    {
                        text: '线路名称',
                        width: 120,
                        sortable: true,
                        align: 'left',
                        dataIndex: 'Roadway'
                    },
                    {
                        text: '起点桩号',
                        width: 80,
                        sortable: true,
                        align: 'left',
                        dataIndex: 'BeginStake'
                    },
                    {
                        text: '终止桩号',
                        width: 80,
                        sortable: true,
                        align: 'left',
                        dataIndex: 'EndStake'
                    },
                    {
                        text: '项目批号',
                        width: 80,
                        sortable: true,
                        align: 'left',
                        dataIndex: 'GrantNumber'
                    },
                    {
                        text: '开工日期',
                        width: 80,
                        sortable: false,
                        align: 'right',
                        renderer: Ext.util.Format.dateRenderer( 'Y/m/d' ),
                        dataIndex: 'StartDate'
                    },
                    {
                        text: '竣工日期',
                        width: 80,
                        sortable: false,
                        align: 'right',
                        renderer: Ext.util.Format.dateRenderer( 'Y/m/d' ),
                        dataIndex: 'CompletionDate'
                    },
                    {
                        text: '项目负责',
                        width: 80,
                        sortable: true,
                        align: 'left',
                        dataIndex: 'ProjectLeader'
                    },
                    {
                        text: '技术负责',
                        width: 80,
                        sortable: true,
                        align: 'left',
                        dataIndex: 'TechnicalChief'
                    },
                    {
                        text: '质检负责',
                        width: 80,
                        sortable: true,
                        align: 'left',
                        dataIndex: 'QualityChief'
                    },
                    {
                        text: '建安预算（万）',
                        width: 100,
                        sortable: true,
                        align: 'right',
                        renderer: Ext.util.Format.numberRenderer( '0,000.00' ),
                        dataIndex: 'Budget'
                    },
                    {
                        text: '建安批复（万）',
                        width: 100,
                        sortable: true,
                        align: 'right',
                        renderer: Ext.util.Format.numberRenderer( '0,000.00' ),
                        dataIndex: 'ApprovedBudget'
                    },
                    {
                        text: '创建日期',
                        width: 80,
                        sortable: true,
                        align: 'right',
                        renderer: Ext.util.Format.dateRenderer( 'Y/m/d' ),
                        dataIndex: 'CreateDate'
                    }
                ]
            }
        );

        $( window ).bind
        ( 
            "resize",
            function ()
            {
                //调整表格宽度
                Common.AdjustGridWidth( 'project-grid', 'body_content' );
            }
        );

        //调整表格宽度
        Common.AdjustGridWidth( 'project-grid', 'body_content' );
    }
);
